package com.dede.applib.extends

import android.app.Activity
import android.content.Intent
import android.os.Parcelable
import java.io.Serializable

/**
 * @author hsh
 * @date 2017/9/26 17:14.
 * @doc
 */
fun Activity.getString(key: String, defaultValue: String): String = this.intent.getStringExtra(key) ?: defaultValue

fun Activity.getInt(key: String, defaultValue: Int): Int = this.intent.getIntExtra(key, defaultValue)

fun Activity.getBoolean(key: String, defaultValue: Boolean): Boolean = this.intent.getBooleanExtra(key, defaultValue)

fun Activity.getFloat(key: String, defaultValue: Float): Float = this.intent.getFloatExtra(key, defaultValue)

fun Activity.getDouble(key: String, defaultValue: Double): Double = this.intent.getDoubleExtra(key, defaultValue)

inline fun <reified T : Parcelable> Activity.getParcelable(key: String): T? = this.intent.getParcelableExtra(key)

inline fun <reified T : Serializable> Activity.getSerializable(key: String): T? = this.intent.getSerializableExtra(key) as T

inline fun <reified T : Parcelable> Activity.getParcelableArrayList(key: String): ArrayList<T> =
        this.intent.getParcelableArrayListExtra<T>(key)


fun Intent.getString(key: String, defaultValue: String): String = this.getStringExtra(key) ?: defaultValue

fun Intent.getInt(key: String, defaultValue: Int): Int = this.getIntExtra(key, defaultValue)

fun Intent.getBoolean(key: String, defaultValue: Boolean): Boolean = this.getBooleanExtra(key, defaultValue)

fun Intent.getFloat(key: String, defaultValue: Float): Float = this.getFloatExtra(key, defaultValue)

fun Intent.getDouble(key: String, defaultValue: Double): Double = this.getDoubleExtra(key, defaultValue)